<?php
/**
 * oscshop2 B2C电子商务系统
 *
 * ==========================================================================
 * @link      http://www.oscshop.cn/
 * @copyright Copyright (c) 2015-2017 oscshop.cn. 
 * @license   http://www.oscshop.cn/license.html License
 * ==========================================================================
 *
 * @author   test
 *
 */
namespace osc\admin\controller;
//require_once '/extend/PHPExcel.php';

use osc\common\service\Excel;
use osc\common\controller\AdminBase;
use think\Db;
class Useticket extends AdminBase{
	
	protected function _initialize(){
		parent::_initialize();
		$this->assign('breadcrumb1','现货提取');
		$this->assign('breadcrumb2','现货提取');		
	}

	


	

	function process()
	{
		$dt['pay_status']=1;
		$dt['pay_time']=time();
		Db::name('valuewd')->where('pay_status',10)->update($dt);
		$this->redirect('value/isprocing');

	}

	function list()
	{

		$param=input('param.');
		
		$query=[];
		$map=null;
		
		if(isset($param['user_name'])){		
			$map['m.username']=['like',"%".$param['user_name']."%"];
			$query['m.username']=urlencode($param['user_name']);
		}
		
		
		
		/*else{
			$map['m.uid']=['gt',0];
		}
		*/
		
		$list=[];
		if($map)
		{
			$list=Db::name('use_ticket')->alias('m')->field('m.*')->where($map)->order('m.create_time desc')->paginate(config('page_num'),false,$query);
		}else
		{
			$list=Db::name('use_ticket')->alias('m')->field('m.*')->order('m.create_time desc')->paginate(config('page_num'),false,$query);
		}
				
		
		$this->assign('list',$list);
				
		$this->assign('empty','<tr><td colspan="20">没有数据~</td></tr>');
		
    	return $this->fetch();
	}
	function info()
	{
		if(request()->isGet()){

			$id=input('param.id');
			if(!$id)
			{
				$this->error('输入的编号不正确');
			}
			$info = Db::name('use_ticket')->where('id',$id)->find();

			$this->assign('info',$info);

		}
		
		if(request()->isPost()){
			$info = input('post.');
			//var_dump($info);
			Db::name('use_ticket')->where('id',$info['id'])->update($info);
			$info = Db::name('use_ticket')->where('id',$info['id'])->find();
			$this->assign('info',$info);

		}

		$this->assign('crumbs','修改');
		return $this->fetch();
	}

	function pay()
	{
		if(request()->isGet()){

			$id=input('param.id');
			if(!$id)
			{
				$this->error('输入的编号不正确');
			}
			$data['order_status'] = 1;
			$info = Db::name('use_ticket')->where('id',$id)->update($data);

			$this->error('更新成功');

		}
		
		
	}

	function send()
	{
		if(request()->isGet()){

			$id=input('param.id');
			if(!$id)
			{
				$this->error('输入的编号不正确');
			}
			$data['order_status'] = 2;
			$info = Db::name('use_ticket')->where('id',$id)->update($data);

			$this->error('更新成功');

		}
		
		
	}



	function export_current()
	{
		$excel=new Excel();
        $table_name="osc_valuewd";
        $field=["username"=>"用户","real_money"=>"到账金额","bankname"=>"开户行","bankaccountname"=>"开户名","bankaccount"=>"银行账号"];
        $map=["pay_status"=>10];        
        $excel->setExcelName("导出")
        ->createSheet("待处理",$table_name,$field,$map)
        ->downloadExcel();
	}



	

	function list_his()
	{
		$param=input('param.');
		
		$query=[];
		$map=null;
		
		if(isset($param['user_name'])){		
			$map['m.username']=['like',"%".$param['user_name']."%"];
			$query['m.username']=urlencode($param['user_name']);
		}
		
		
		
		/*else{
			$map['m.uid']=['gt',0];
		}
		*/
		
		$list=[];
		if($map)
		{
			$list=Db::name('user_value')->alias('m')->field('m.*')->where($map)->order('m.creat_time desc')->paginate(config('page_num'),false,$query);
		}else
		{
			$list=Db::name('user_value')->alias('m')->field('m.*')->order('m.creat_time desc')->paginate(config('page_num'),false,$query);
		}
				
		
		$this->assign('list',$list);
				
		$this->assign('empty','<tr><td colspan="20">没有数据~</td></tr>');
		
    	return $this->fetch();
	}

	function getprice()
	{
		if(request()->isPost()){
			
			$data=input('post.');
			//var_dump($data);
			
			if($data['delivery_date'])
			{
				$year=((int)substr($data['delivery_date'],0,4));//取得年份

				$month=((int)substr($data['delivery_date'],5,2));//取得月份

				$day=((int)substr($data['delivery_date'],8,2));//取得几号 

			    //$dt = strtotime($data['delivery_date']." - 1 day");
			    //$data['delivery_date'] = date('Y-m-d',strtotime($data['delivery_date']." - 1 day")); 
				$dt1 = $data['delivery_date'] ;
			    $data['delivery_date']=date('Y-m-d',strtotime("$dt1 -1 day"));
				//date('Y-m-d H:i:s', 1156219870); 
					//var_dump($data['delivery_date']);


				$ret = Db::name('value_config')->where('dt',$data['delivery_date'])->where('exchange_id',$data['exchange_id'])->where('variety_id',$data['variety_id'])->find();

				//return $ret;
				//var_dump($ret);
				$dt['rate']=0;
				if($ret)
				{
					$dt['rate'] = $ret['rate'];
				}
				
				//$dt['username'] = $ret['username'];
				//$dt['idcard'] = $ret['username'];
				//$dt = $ret['username'];
				//echo json_encode($dt['nickname'],JSON_UNESCAPED_UNICODE);
				return array($dt['rate']);
				
			}


		}
	}

	function config()
	{
		$param=input('param.');
		//var_dump($param);
		//die;
		
		$query=[];
		$map=null;

		$query=[];

		$map = null;
		if(isset($param['exchange_id']))
		{
			if($param['exchange_id']!="-1")
			{
				$map['exchange_id']=['eq',$param['exchange_id']];
			}
		}
		if(isset($param['variety_id']))
		{
			if($param['variety_id']!="-1")
			{
				$map['variety_id']=['eq',$param['variety_id']];
			}
		}

		if(isset($param['trade_dt'])){		
			$map['dt']=['eq',$param['trade_dt']];
		}

		//$map['admin_state']=['>=',1];
		/*else{
			$map['m.uid']=['gt',0];
		}
		*/
		$list=[];
		//var_dump($param['num']);
		
		$li=null;
		if($map)
		{
			$list=Db::name('value_config')->alias('m')->field('m.*')->where($map)
		->order('m.dt desc')->paginate(40,false,$query);
			$li = $list;
		}else
		{
			$list=Db::name('value_config')->alias('m')->field('m.*')->order('m.dt desc')->paginate(40,false,$query);
			$li = $list;
		}


		
	
		
		
		/*else{
			$map['m.uid']=['gt',0];
		}
		*/
		

		//$list=Db::name('value_config')->order('dt desc')->paginate(config('page_num'),false,$query);
				
				//查询交易所
		$exchange = Db::name('exchange_house')->where('state',1)->select();
		$variety = Db::name('exchage_variety')->where('state',1)->select();
		$this->assign('exchange',$exchange);
		$this->assign('variety',$variety);
		$this->assign('list',$list);
				
		$this->assign('empty','<tr><td colspan="20">没有数据~</td></tr>');
		
    	return $this->fetch();

	}

	function edit()
	{
		if(request()->isPost())
		{
			$data=input('post.');
			$dt['exchange_id'] = $data['exchange_id'];
			$dt['variety_id'] = $data['variety_id'];
			$dt['dt'] = $data['trade_dt'];
			$dt['rate'] = $data['rate'];



			$rt = Db::name('value_config')->where('exchange_id',$dt['exchange_id'])->where('variety_id',$dt['variety_id'])->where('dt',$dt['dt'])->find();
			if($rt)
			{
				Db::name('value_config')->where('exchange_id',$dt['exchange_id'])->where('variety_id',$dt['variety_id'])->where('dt',$dt['dt'])->update($dt);
			}else
			{
				Db::name('value_config')->insert($dt);

			}
			$this->redirect('value/config');
		}
		$exchange = Db::name('exchange_house')->where('state',1)->select();
		$variety = Db::name('exchage_variety')->where('state',1)->select();
		$this->assign('exchange',$exchange);
		$this->assign('variety',$variety);
		$this->assign('breadcrumb1','收盘价管理');
		$this->assign('breadcrumb2','收盘价管理');	
		$this->assign('crumbs','收盘价管理');
		return $this->fetch();
	}


}
?>